clear;clc;
%% create session 
% using device file: [Constant.AutoMeasurementRootPath '\+MeasurementSession\@SimpleMeasurement\SIMLE_DEVICE.dat']
s=MeasurementSession.SimpleMeasurement();


%% get devices
tek=s.getDevice('tek');
zi=s.getDevice('dev3543');
laser64=s.getDevice('toptica64');


%% 
sweeper = zi.sweepModule();
sweeper.setControl('xmapping', 1, 'start', 10e3, 'stop', 80e3)...
       .setFilter('bandwidthcontrol', 0)...
       .setSettling('settling_tc', 1)...
       .setStatistics('averaging_sample', 100)...
       .setOption()...
       .showParam();

%%
scanVoltList = 80:0.1:95;

sweeper.subscribeChannel('0');
result = sweeper.batchSweep(@batch_fun, 1:length(scanVoltList), ...
                            'scanVolt', scanVoltList, 'laserObj', laser64);
sweeper.unsubscribeChannel('0');

%%
function res = batch_fun(swpr, idx, varargin)
    p=inputParser;
    p.addParameter('scanVolt', 3.0);
    p.addParameter('laserObj', '');
    p.parse(varargin{:});

    scanVolt = p.Results.scanVolt;
    laser = p.Results.laserObj;
    
    % do something here
    disp(scanVolt(idx));
    laser.disableScan().setScanOffsetVolt( scanVolt(idx) );
    pause(5);

    % do the sweep
    res = swpr.run('index', idx, 'silence', 0);
end
